<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class BaseModel extends Model
{
    public function add(array $inser_data,array $hiddent_property=[]):bool {
        if(count($hiddent_property)==0) {
            return $this->insert($inser_data);
        }else{
            return $this->insert($this->filter($inser_data,$hiddent_property));
        }
    }

    /*添加代码*/
    private function insert(array $inser_data){
        $model = new static();
        foreach ($inser_data as $k=>$v){
            $model[$k]=$v;
        }
        return $model->save();
    }

    /*过滤不要的字段*/
    private function filter(array $data,array $hiddent):array {
        foreach ($hiddent as $k=>$v){
            if(isset($hiddent[$k]))
                unset($data[$k]);
        }
        return $data;
    }
}
